package com.material.common.utils;

import net.sourceforge.pinyin4j.PinyinHelper;

public class PinyinUtils {

    public static String getFirstLetters(String chinese) {
        StringBuilder initials = new StringBuilder();
        for (char c : chinese.toCharArray()) {
            String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(c);
            if (pinyinArray != null && pinyinArray.length > 0) {
                // 取第一个拼音的首字母
                initials.append(pinyinArray[0].charAt(0));
            } else {
                // 非汉字保留原字符
                initials.append(c);
            }
        }
        return initials.toString();
    }

}
